Conversation
|
@danteissaias is attempting to deploy a commit to the Zero Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe pull request introduces functionality for managing trusted senders within the email application. It adds a new form field in the settings page for handling a list of trusted sender emails, updates the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant MI as MailIframe
participant S as Server/API
U->>MI: Click "Trust Sender" button
MI->>S: Invoke onTrustSender(senderEmail)
S-->>MI: Return success or failure
alt Success
MI->>U: Update UI (enable images for trusted sender)
else Failure
MI->>U: Display error toast
end
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
apps/mail/components/mail/mail-iframe.tsx (1)
101-106: Consider conditionally rendering the Trust Sender button.The "Trust Sender" button is currently always shown when images are hidden, even if the sender is already trusted. Consider conditionally rendering this button only when the sender is not already trusted.
- <button - onClick={() => void onTrustSender(senderEmail)} - className="ml-2 cursor-pointer underline" - > - {t('common.actions.trustSender')} - </button> + {!isTrustedSender && ( + <button + onClick={() => void onTrustSender(senderEmail)} + className="ml-2 cursor-pointer underline" + > + {t('common.actions.trustSender')} + </button> + )}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/mail/app/(routes)/settings/general/page.tsx(4 hunks)apps/mail/components/mail/mail-display.tsx(1 hunks)apps/mail/components/mail/mail-iframe.tsx(2 hunks)apps/mail/locales/en.json(2 hunks)packages/db/src/user_settings_default.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
apps/mail/components/mail/mail-iframe.tsx (4)
apps/mail/hooks/use-settings.ts (1)
useSettings(7-38)packages/db/src/user_settings_default.ts (1)
defaultUserSettings(3-10)apps/mail/lib/timezones.ts (1)
getBrowserTimezone(1-1)apps/mail/actions/settings.ts (1)
saveUserSettings(53-88)
apps/mail/app/(routes)/settings/general/page.tsx (2)
apps/mail/components/ui/form.tsx (4)
FormField(169-169)FormItem(164-164)FormLabel(165-165)FormDescription(167-167)apps/mail/components/ui/tooltip.tsx (3)
Tooltip(59-59)TooltipTrigger(59-59)TooltipContent(59-59)
🪛 Biome (1.9.4)
apps/mail/app/(routes)/settings/general/page.tsx
[error] 279-279: Missing key property for this element in iterable.
The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.
(lint/correctness/useJsxKeyInIterable)
🔇 Additional comments (12)
apps/mail/components/mail/mail-display.tsx (1)
371-371: Successfully implemented sender email prop to MailIframe.The addition of the
senderEmailprop to theMailIframecomponent enables the trusted sender functionality, allowing the component to determine if the current sender is in the user's trusted list.packages/db/src/user_settings_default.ts (3)
9-10: Good addition of trustedSenders field to default settings.The empty array initialization is appropriate as users start with no trusted senders.
18-18: Well-defined schema for trustedSenders.Using
z.string().array()properly defines the expected data type for validation.
21-21: Improved type safety by deriving from schema.Changing from
typeof defaultUserSettingstoz.infer<typeof userSettingsSchema>ensures that the types are derived from the validation schema, making the system more robust against mismatches.apps/mail/app/(routes)/settings/general/page.tsx (3)
45-45: Good schema definition for trustedSenders.The schema correctly defines trusted senders as an array of strings.
140-140: Appropriate default initialization.Initializing
trustedSendersas an empty array aligns with the default settings.
279-296: Well-implemented sender removal functionality.The remove button with tooltip provides a good user experience for managing trusted senders. The implementation correctly filters out the removed sender from the array.
🧰 Tools
🪛 Biome (1.9.4)
[error] 279-279: Missing key property for this element in iterable.
The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.(lint/correctness/useJsxKeyInIterable)
apps/mail/locales/en.json (3)
37-37: Good addition of 'Trust Sender' translation.This translation entry supports the new button in the mail interface.
40-40: Added 'Remove' translation for UI consistency.This translation will be used for the remove button in the trusted senders list.
308-309: Clear and descriptive translations for trusted senders section.These translations effectively communicate the purpose of the trusted senders feature to the user.
apps/mail/components/mail/mail-iframe.tsx (2)
12-17: Well implemented parameter addition for tracking trusted senders.The added
senderEmailparameter and the logic to check if a sender is trusted are well implemented. The code correctly initializes theimagesEnabledstate based on whether the sender is trusted or external images are globally enabled.
2-10: Proper organization of imports.The imports have been well organized, with appropriate separation of internal and external dependencies.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
apps/mail/components/mail/mail-iframe.tsx (2)
22-42: Prevent duplicate entries in trustedSenders arrayThe current implementation doesn't check if the sender is already in the trusted list before adding it, which could lead to duplicate entries.
const onTrustSender = useCallback(async (senderEmail: string) => { setImagesEnabled(true); const existingSettings = settings ?? { ...defaultUserSettings, timezone: getBrowserTimezone(), }; const { success } = await saveUserSettings({ ...existingSettings, trustedSenders: settings?.trustedSenders - ? settings.trustedSenders.concat(senderEmail) + ? settings.trustedSenders.includes(senderEmail) + ? settings.trustedSenders + : settings.trustedSenders.concat(senderEmail) : [senderEmail], }); if (!success) { toast.error('Failed to trust sender'); } else { mutate(); } }, [settings, mutate]);
12-17: 🛠️ Refactor suggestionConsider validating
senderEmailfor edge casesSince
senderEmailis now a required prop and used in critical checks, you should add validation to handle edge cases like empty strings or undefined values.export function MailIframe({ html, senderEmail }: { html: string; senderEmail: string }) { + const validSenderEmail = senderEmail?.trim() || ''; const { settings, mutate } = useSettings(); - const isTrustedSender = settings?.trustedSenders?.includes(senderEmail); + const isTrustedSender = settings?.trustedSenders?.includes(validSenderEmail); const [imagesEnabled, setImagesEnabled] = useState( isTrustedSender || settings?.externalImages || false, );
🧹 Nitpick comments (3)
apps/mail/components/mail/mail-iframe.tsx (3)
101-106: Hide or disable the trust button for already trusted sendersThe "Trust Sender" button is always visible, even if the sender is already in the trusted senders list. This could confuse users who might try to trust a sender multiple times.
{!imagesEnabled && !settings?.externalImages && ( <div className="flex items-center justify-start bg-amber-500 p-2 text-sm text-amber-900"> <p>{t('common.actions.hiddenImagesWarning')}</p> <button onClick={() => setImagesEnabled(!imagesEnabled)} className="ml-2 cursor-pointer underline" > {imagesEnabled ? t('common.actions.disableImages') : t('common.actions.showImages')} </button> + {!isTrustedSender && ( <button onClick={() => onTrustSender(senderEmail)} className="ml-2 cursor-pointer underline" > {t('common.actions.trustSender')} </button> + )} </div> )}
37-41: Improve error handling for saveUserSettingsThe current error handling only shows a toast message. Consider adding more robust error handling to provide a better user experience, especially for network failures.
if (!success) { toast.error('Failed to trust sender'); + // Revert UI state since operation failed + setImagesEnabled(settings?.externalImages || false); } else { mutate(); + toast.success(t('common.actions.senderTrusted')); }
30-35: Add a helper function for managing trusted sendersThe logic for updating the trusted senders array could be extracted into a reusable helper function for better maintainability and to ensure consistent behavior across the application.
+// Add this helper function at the top of the file or in a separate utility file +const addTrustedSender = (currentList: string[] = [], newSender: string): string[] => { + if (!newSender || currentList.includes(newSender)) { + return currentList; + } + return [...currentList, newSender]; +}; // Then in the component const { success } = await saveUserSettings({ ...existingSettings, - trustedSenders: settings?.trustedSenders - ? settings.trustedSenders.concat(senderEmail) - : [senderEmail], + trustedSenders: addTrustedSender(settings?.trustedSenders, senderEmail), });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/mail/components/mail/mail-iframe.tsx(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/components/mail/mail-iframe.tsx (4)
apps/mail/hooks/use-settings.ts (1)
useSettings(7-38)packages/db/src/user_settings_default.ts (1)
defaultUserSettings(3-10)apps/mail/lib/timezones.ts (1)
getBrowserTimezone(1-1)apps/mail/actions/settings.ts (1)
saveUserSettings(53-88)
|
@danteissaias - I think we discussed in discord, but you are also doing these two yea?
|
Yeah, I'll take a look at doing these in follow-up PRs. |
|
love this. lets make the area a Scroll Area so that when there are more than 5-6 we can scroll and see more |
|
Pushed a couple changes:
|
Description
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
N/A
Screenshots/Recordings
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes